# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=beaker

pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}" "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=1.6.4
pkgrel=2
pkgdesc="Caching and sessions WSGI middleware for use with web applications and stand-alone Python scripts and applications (mingw-w64)"
arch=('any')
license=('custom')
url="http://beaker.groovie.org/"
depends=("${MINGW_PACKAGE_PREFIX}-python2-setuptools" "${MINGW_PACKAGE_PREFIX}-python3-setuptools")
source=("http://cheeseshop.python.org/packages/source/B/Beaker/Beaker-${pkgver}.tar.gz")
md5sums=('c2e102870ed4c53104dec48ceadf8e9d')
 
prepare() {
  cd "${srcdir}/Beaker-${pkgver}"
  #patch -p1 -i ${srcdir}/mingw-python-fix.patch

  cd "${srcdir}"
  cp -r Beaker-${pkgver} python2-Beaker-${pkgver}
  cp -r Beaker-${pkgver} python3-Beaker-${pkgver}
}

build() {
  cd "${srcdir}/python3-Beaker-${pkgver}"
  sed -i "s#/usr/bin/python#/usr/bin/python3#" beaker/crypto/pbkdf2.py
  ${MINGW_PREFIX}/bin/python3 setup.py build

  cd "${srcdir}/python2-Beaker-${pkgver}"
  sed -i "s#/usr/bin/python#/usr/bin/python2#" beaker/crypto/pbkdf2.py
  ${MINGW_PREFIX}/bin/python2 setup.py build
}

package_python3-beaker() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3")

  cd "${srcdir}/python3-Beaker-${pkgver}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=;--install-purelib=;--install-data=" \
    ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" --optimize=1
  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-beaker/LICENSE"
}
 
package_python2-beaker() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2>")

  cd "${srcdir}/python2-Beaker-${pkgver}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=;--install-purelib=;--install-data=" \
    ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" --optimize=1
  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-beaker/LICENSE"
}

package_mingw-w64-i686-python2-beaker() {
  package_python2-beaker
}

package_mingw-w64-i686-python3-beaker() {
  package_python3-beaker
}

package_mingw-w64-x86_64-python2-beaker() {
  package_python2-beaker
}

package_mingw-w64-x86_64-python3-beaker() {
  package_python3-beaker
}
